<?php
error_reporting(4);
require_once("config.php");
require_once("header.php");
if (!$allow_url_fopen) {
	echo '<span class="error"><b>Note</b>: Please enable \'<em>allow_url_fopen</em>\' option in PHP configuration file</span><br/>';
}

require_once("MSN.php");
require_once("Google.php");
require_once("yahoo.php");

$y = new Yahoo();
$g = new Google();
$m = new MSN();

$urlarr[0] = $_REQUEST['urlBox1'];
$urlarr[1] = $_REQUEST['urlBox2'];
$urlarr[2] = $_REQUEST['urlBox3'];
$urlarr[3] = $_REQUEST['urlBox4'];

$results = array();
$totals = array();

foreach ($urlarr as $key => $url ) {
	if ( !empty($url) ) {
		$results[$key][] = $y->get_popularity($url);
		$results[$key][] = $g->get_response($url);
		$results[$key][] = $m->get_response($url);
		$totals[$key] = array_sum($results[$key]);
	}
}
asort($totals);
reset($totals);

?><br />
<table width="98%" border="0">
  <tr class="headingbar">
    <td height="25" align="center" valign="middle"><strong>URL</strong></td>
    <td height="25" align="center" valign="middle"><strong>Yahoo</strong></td>
    <td height="25" align="center" valign="middle"><strong>Google</strong></td>
    <td height="25" align="center" valign="middle"><strong>MSN</strong></td>
    <td height="25" align="center" valign="middle"><strong>Total</strong></td>
  </tr>
  <?php
  $row = 0;
  foreach($totals as $key => $total ){
  ?>
  <tr class="<?php if($row % 2) echo "tr1"; else echo "tr2";?>">
    <td height="22"><?php echo $urlarr[$key]; ?></td>
    <td height="22" align="center"><?php echo $y->get_url(number_format($results[$key][0]), $urlarr[$key]); ?></td>
    <td height="22" align="center"><?php echo $g->get_url(number_format($results[$key][1]), $urlarr[$key]); ?></td>
    <td height="22" align="center"><?php echo $m->get_url(number_format($results[$key][2]), $urlarr[$key]); ?></td>
    <td height="22" align="center"><?php echo number_format($total); ?></td>
  </tr>
  <?php
  $row++;
  }
  ?>
</table>
<?php
require_once("footer.php");
?>
